
$('#upload-pic').fileupload({
	url : "/file/picUpload?model=hikPicture",
	dataType : 'json',
	add : function(e, data) {
		golbal.progress("正在上传文件...");
		data.submit();
	},
	done : function(e, result) {
		if(result.result.success == 1){
			$.messager.progress("close");
			var picPath =  result.result.others.filePath;
			$("#defaultPic").hide();
			$("<li><img  class='viewer-toggle' data-path='"+picPath+"' src="+img_server+picPath+" width='200px' height='150px' alt="+$("#resourceName").val()
					+"/><div class='close_img' onclick='deleteImg(this)'>X</div></li>").appendTo($("#picUL"));
			$('img').viewer();
			picArr.push(picPath); 
		}
	}
});
$('#upload-video').fileupload({
	url : "/file/picUpload?model=hikVideo",
	dataType : 'json',
	add : function(e, data) {
		golbal.progress("正在上传文件...");
		data.submit();
	},
	done : function(e, result) {
		if(result.result.success == 1){
			$.messager.progress("close");
			var filePath =  result.result.others.filePath;
			var fileName = result.result.others.name;
			$("#videoUL").hide();
			$("<li style='list-style:none;border-bottom:solid 1px #ddd;'>"+fileName+"<a href='javascript:void(0)' class='btn btn-xs btn-danger' data='"+filePath+"' onclick='deleteVideoPath(this)'>删除</a></li>").appendTo($("#videoULPath"));
			videoArr.push(filePath); 
		}
	}
});

function goPlayPage(obj){
	var filePath = $(obj).attr("data-url");
	var fileName = $(obj).attr("data-filename");
	url ="/video/plan/play_video?filePath="+filePath;
	var _customerClass = ($(obj).attr("customer-id") == undefined) ? "customer-id": $(obj).attr("customer-id");
	$("<div/>").addClass("customer-dialog " + _customerClass).window({
			width : '96%',
			height : '96%',
			modal : true,
			minimizable : false,
			resizable : false,
			title : "<i class=\"iconfont icon-windows\"></i>播放::" + fileName,
			border : false,
			onClose : function() {
				$(this).window('destroy');
				$(".easyui-datagrid").datagrid("reload");
				$(".easyui-treegrid").treegrid("reload");
			},
			href : url
		});
	return false;
}

function save(obj){
	var $form = $(obj).parents("form");
	var $url = _ctx+$form.attr("action");
	if (!$form.form("validate")) {// 验证没通过，返回
		return false;
	}
	var s_leadId = $("#leader-tree").tree("getChecked");
	var leadId =0;
	if(s_leadId && s_leadId.length>0){
		 leadId = s_leadId[0].id.substring(s_leadId[0].id.indexOf("_")+1);
	}
	golbal.progress();
	$form.ajaxSubmit({
		url :$url, 
		type:"POST",
		data:{"picAddress":picArr.join(","),"videoAddress":videoArr.join(","),"leaderId":leadId},
		success : function(msg) {
			$.messager.progress("close");
			if (msg.success == 1) {
				layer.alert(msg.msg || "添加成功！", {
					icon : 1,
					skin : "layer-ext-moon",
				}, function(index) {
					layer.close(index);
					closeDialog(obj);
					$("#planResource-datagrid").datagrid("reload");
					$("#look-videoPlan-datagrid").datagrid("reload");
				});
			} else {
				layer.alert("添加失败！请稍候重试：" + (msg.msg || ""), {
					icon : 2,
					skin : "layer-ext-moon",
				}, function(index) {
					layer.close(index);
					window.close()
					if (msg.o != undefined && $backUrl) {
						window.location.href = $backUrl;
					}
				});
			}
		}
	 });
	return false;
}